IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_sp_GetUserForManagement]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[cms_sp_GetUserForManagement]
GO
create procedure [dbo].[cms_sp_GetUserForManagement]
@UserId int
as
select 
	Users.UserId,
	Users.SiteId,
	Users.SiteGroupId,
	Users.LoginName,
	Users.UserEmail,
	Users.UserName,
	UserPasswords.PasswordHash,
	UserPasswords.PasswordSalt,
	UserPasswords.IsInitial,
	Users.IsEnabled,
	Users.IsSystem,
	Users.CreatedBy,
	Users.DateCreated,
	Users.LastUpdatedBy,
	Users.DateLastUpdated
from [dbo].[Users]
inner join [dbo].[UserPasswords]
	on UserPasswords.UserId = Users.UserId
where Users.UserId = @UserId	
select 
	[UserGroups].[UserGroupId],
	[UserGroups].[SiteId],
	[UserGroups].[SiteGroupId],
	[UserGroups].[GroupName],
	[UserGroups].[IsEnabled],
	[UserGroups].[IsSystem],
	[UserGroups].[CreatedBy],
	[UserGroups].[DateCreated],
	[UserGroups].[LastUpdatedBy],
	[UserGroups].[DateLastUpdated]
from [dbo].[UserGroups]
inner join [dbo].[UserGroupLinks]
	on [UserGroupLinks].[UserGroupId] = [UserGroups].[UserGroupId]
inner join [dbo].[Users]
	on [Users].[UserId] = [UserGroupLinks].[UserId]
where [Users].[UserId] = @UserId


GO

